package com.ruoyi.framework.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import com.ruoyi.common.annotation.ApiEncrypt;

/**
 * API加密拦截器
 * 简化版本，主要用于日志记录
 * 
 * @author ruoyi
 */
public class ApiEncryptInterceptor implements HandlerInterceptor
{
    private static final Logger log = LoggerFactory.getLogger(ApiEncryptInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 由于已经使用ApiEncryptFilter处理解密，这里只做简单的日志记录
        if (handler instanceof HandlerMethod) {
            HandlerMethod handlerMethod = (HandlerMethod) handler;
            
            // 检查类级别的@ApiEncrypt注解
            ApiEncrypt classApiEncrypt = handlerMethod.getBeanType().getAnnotation(ApiEncrypt.class);
            // 检查方法级别的@ApiEncrypt注解
            ApiEncrypt methodApiEncrypt = handlerMethod.getMethodAnnotation(ApiEncrypt.class);
            
            if (classApiEncrypt != null || methodApiEncrypt != null) {
                log.debug("请求 {} 需要加密处理，已由ApiEncryptFilter处理", request.getRequestURI());
            }
        }
        
        return true;
    }
}